<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
  data() {
    return {
      apiUrl: {
        addLabel: "mall-site-portal/member/batchMemberTag", //添加标签
        labelList: "mall-site-portal/member/listMemberTag",
      },

      labelList: [], //标签列表
      checkedList: [], //已选中的标签  存id

      isloading: true,

      showDialog: false,
    };
  },
  methods: {
    // 获取标签列表
    async getLabelList() {
      let res = await this.$vFN.Http.post(
        {
          url: this.apiUrl.labelList,
        },
        window
      );

      console.log(res);
      if (res._ok) {
        // 对标签列表进行更改，添加一个isChecked 属性
        this.labelList = res.data.map((item) => {
          return {
            ...item,
            isChecked: false,
          };
        });
        this.isloading = false;
        // console.log(this.labelList);
      }
    },

    // 点击了多选
    handleCheck(index_) {
      this.checkedList = [];
      console.log(index_);
      this.labelList[index_].isChecked = !this.labelList[index_].isChecked;

      this.labelList.forEach((item2, index2) => {
        if (item2.isChecked) {
          this.checkedList.push(item2.id);
        }
      });

      // console.log("this.checkedList", this.checkedList);
    },

    async submit() {
      let res = await this.$vFN.Http.post(
        {
          url: this.apiUrl.addLabel,
          data: {
            memberIdLst: this.userArr, //从上一层传来
            tagIdLst: this.checkedList,
          },
        },
        window
      );

      if (res._ok) {
        this.$vFN.Tools.messageSuccess(res.message);
        this.onSuccess();
        this.showDialog = false;
      }
    },

    init() {
      this.showDialog = true;
      this.getLabelList();
    },

    // 回调
    onSuccess() {},

    // 关闭
    handleClose() {
      this.showDialog = false;
    },

    // 点击取消
    cancelDialog() {
      this.showDialog = false;
    },
  },
  mounted() {
    this.init();
  },
};
</script>